package site.shenjie.eureka.ribbon.feign.config;

import com.alibaba.fastjson.JSONObject;
import feign.FeignException;
import feign.Response;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.lang.reflect.Type;

public class MyDecoder implements Decoder {
    @Override
    public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
        System.out.println("正在进行解码...");
        String result = IOUtils.toString(response.body().asInputStream(), "UTF-8");
        return JSONObject.toJSONString(result.replace("Hello", "Welcome to "));
    }
}
